local yiyi = fk.CreateSkill {
    name = "ys__yiyi",
}


Fk:loadTranslationTable {
["ys__yiyi"] = "依依",
[":ys__yiyi"] = "每回合限一次，准备阶段或结束阶段，你可以与一名其他角色拼点，然后你令没赢的角色选择一项：1.受到1点无来源伤害；2.弃置两张牌。",
["#yiyi-lose"] = "弃置两张牌，否则受到1点无来源伤害。",
["#yiyi-choose"] = "与一名角色拼点，令没赢的角色获得减益。",
}



ChooseYiyi = function(target)
    local room = target.room
    local discards = room:askToDiscard(target, {
        min_num = 2,
        max_num = 2,
        include_equip = true,
        skill_name = yiyi.name,
        cancelable = true,
        prompt = "#yiyi-lose"
    })
    if #discards == 0 then
        room:damage{
            from = nil,
            to = target,
            damage = 1,
            skillName = yiyi.name,
        }
    end
end


yiyi:addEffect(fk.EventPhaseStart, {
    can_trigger = function (self, event, target, player, data)
        return (not player:isKongcheng()) and (player.phase == player.Start or player.phase == player.Finish) and (player:hasSkill(yiyi.name)) and player:usedSkillTimes(yiyi.name, Player.HistoryTurn) == 0
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local aa = room:getOtherPlayers(player, false)
        local bb = { }
        local p = 1
        while(aa[p] ~= nil) do
            if (not aa[p]:isKongcheng()) then table.insert(bb, aa[p]) end
            p = p + 1
        end
        local tgt = room:askToChoosePlayers(player, {
            min_num = 1,
            max_num = 1,
            targets = bb,
            skill_name = yiyi.name,
            prompt = "#yiyi-choose",
            cancelable = true,
        })[1]
        if tgt ~= nil then
           local pindian = player:pindian({tgt}, yiyi.name)
            if player.dead then return end
            if pindian.results[tgt].winner == player then
                ChooseYiyi(tgt)
            else 
                if pindian.results[tgt].winner == tgt then
                    ChooseYiyi(player)
                else
                    ChooseYiyi(tgt)
                    ChooseYiyi(player)
                end
            end
        end
    end,
})

return yiyi